package org.example.videotran.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

public class JsonUtils {
    public static Object JsonStringToObject(String json) throws JsonProcessingException {
        return new ObjectMapper().readValue(json, Object.class);
    }

    public static String objectToJson(Object data) throws JsonProcessingException {
        return new ObjectMapper().writeValueAsString(data);
    }

    public static String getData(String body,String name){
        try {
            // 使用 ObjectMapper 解析 JSON 字符串
            ObjectMapper objectMapper = new ObjectMapper();
            JsonNode jsonNode = objectMapper.readTree(body);

            // 获取特定的属性值
            return jsonNode.get(name).asText();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}
